<div id="imageItemUpload" >
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title pull-left"> 类型配置 </h3>
                    <button type="button" v-on:click="jumpToList()" class="btn btn-primary pull-right" style="margin-top: -7px">返回</button>
                    <br/>
                </div>
                <div class="panel-body">
                    <!--表单部分-->
                    <div class="col-md-12 column">
                        <form class="form-horizontal" role="form" name="submitForm"  ref="submitForm"  v-bind:action="submitUrl">
                            <div class="form-group"  >
                                <label for="inputFile0" class="col-sm-2 control-label">字典ID：</label>
                                <div class="col-sm-10">
                                    <input type="text"  v-model="dictDto.id" class="form-control" id="inputFile0" disabled="disabled"/>
                                </div>
                            </div>
                            <div class="form-group"  >
                                <label for="inputFile1" class="col-sm-2 control-label">类型编码：</label>
                                <div class="col-sm-10">
                                    <input type="text"  v-model="dictDto.codeType" class="form-control" id="inputFile1" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputFile2" class="col-sm-2 control-label">类型名称：</label>
                                <div class="col-sm-10">
                                    <input v-model="filePath" type="text"  v-model="dictDto.typeName"  class="form-control" id="inputFile2" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputFile3" class="col-sm-2 control-label">字典编码：</label>
                                <div class="col-sm-10">
                                    <input v-model="filePath" type="text"  v-model="dictDto.codeCode" class="form-control" id="inputFile3" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="inputFile4" class="col-sm-2 control-label">字典值：</label>
                                <div class="col-sm-10">
                                    <input v-model="filePath" type="text"  v-model="dictDto.codeValue" class="form-control" id="inputFile4" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button type="button" v-on:click="submit" class="btn btn-primary btn-lg btn-block "   v-if="isShow">提交保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    //采用vue
    var dictAdd=new Vue({
        el: '#imageItemUpload',
        data: {
            //提交的url
            submitUrl:  Vue.prototype.getUrl('/config/dict/save'),
            dictDto:{
                id:null,
                codeType:'',
                typeName:'',
                codeCode:'',
                codeValue:'',
            },
            filePath : '',
            isEdit : false,
            isShow : true,
        },
        methods: {
            submit: function() {
                if(!this.submitCheck()){ //数据校验
                    return false;
                }
                //走提交流程
                this.$http.post(this.submitUrl,this.dictDto).then(function(data){
                    if(data.data.success){
                        this.isShow = false;
                        alert("保存成功");
                    }else{
                        alert("保存失败："+data.data.errorMessage);
                    }

                }).catch(function(){
                    alert('服务器异常！');
                });

            },
            jumpToList:function() {
                //加载页面
                loadPageToBodyMain('/show/config/dict/dictList');
            },
            //提交表单前的验证
            submitCheck:function(){
                if(this.dictDto.codeType.length == 0){
                    alert('类型编码不能为空！！');
                    return false;
                }else if(this.dictDto.typeName.length == 0){
                    alert('类型名称不能为空！！');
                    return false;
                }else if(this.dictDto.codeCode.length == 0){
                    alert('字典编码不能为空！！');
                    return false;
                }else if(this.dictDto.codeValue.length == 0){
                    alert('字典值不能为空！！');
                    return false;
                }
                return true;
            }
        },
    });

    //重写厂商自动下拉方法
    Vue.prototype.$registerDictTopAuto('#inputFile1',function(item) {
        dictAdd.dictDto.codeType = item.codeType; //设置id的值
        dictAdd.dictDto.typeName = item.typeName; //设置id的值
    });
</script>
<!--</body>-->
<!--</html>-->